package com.jiang.daily.Q2012;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/03/11 22:09
 */
class Solution {
    public int sumOfBeauties(int[] nums) {
        int n = nums.length;
        int min = nums[0];
        int max = nums[n - 1];
        boolean[] dp = new boolean[n];
        int res = 0;
        for (int i = 1; i < n - 1; i++) {
            if (nums[i] > nums[i - 1] && nums[i] < nums[i + 1]) {
                res += 1;
            }
            if (nums[i] > min) {
                min = nums[i];
                dp[i] = true;
            }
        }

        for (int i = n - 1; i >= 1; i--) {
            if (nums[i] < max) {
                if (dp[i])  res += 1;
                max = nums[i];
            }
        }
        return res;
    }
}
